import { contentCensor as AipContentCensor } from 'baidu-aip-sdk';
import { BAIDU_AI_APP_ID, BAIDU_AI_SECRET_KEY, BAIDU_AI_APP_KEY } from '../config';

export default async function textCheck(text = '') {
  const client = new AipContentCensor(BAIDU_AI_APP_ID, BAIDU_AI_APP_KEY, BAIDU_AI_SECRET_KEY);

  return new Promise((resolve, reject) => {
    client.textCensorUserDefined(text).then(
      function (result) {
        if (!result || !result.conclusion) reject(new Error('百度内容检测失败'));
        resolve(result.conclusion);
      },
      function (err) {
        throw err;
      }
    );
  });
}
